//
//  ViewController.m
//  12-18
//
//  Created by mac on 15-12-18.
//  Copyright (c) 2015年 lee. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
{
    UILabel *view;
    CGFloat *lasteScale;
    
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.title = @"我日";
    self.view.backgroundColor = [UIColor blackColor];
    
    view = [[UILabel alloc]initWithFrame:CGRectMake(50, 200, 80, 80)];
    view.userInteractionEnabled = YES;
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(onPan:)];
    [view addGestureRecognizer:pan];
    
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(onPinch:)];
    [view addGestureRecognizer:pinch];
    
    UIRotationGestureRecognizer *rot = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(onRot:)];
    [view addGestureRecognizer:rot];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTap:)];
    [view addGestureRecognizer:tap];
}



- (void)onTap:(UITapGestureRecognizer *)tap{
    
}

- (void)onRot:(UIRotationGestureRecognizer *)rot{
    rot.view.transform = CGAffineTransformMakeRotation(rot.rotation);
}

- (void)onPinch:(UIPinchGestureRecognizer *)pinch{
    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale,pinch.scale);
}

- (void)onPan:(UIPanGestureRecognizer *)pan{
    CGPoint p = [pan translationInView:self.view];
//    CGRect rect = pan.view.frame;
//    rect.origin.x += p.x;
//    rect.origin.y += p.y;
//    pan.view.frame = rect;
    pan.view.transform = CGAffineTransformTranslate(pan.view.transform, p.x, p.y);
    
    [pan setTranslation:CGPointZero inView:self.view];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
